<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Category extends CI_Controller {
	public function __construct(){
		parent::__construct();
		$this->load->model('m_category');
	}

	function add_category_process() {
		if($this->input->post('btn_cat_add') !=""){
			$ad_cat['cat_name'] = $this->input->post('cat_name');
			$ad_cat['cat_icon'] = $this->input->post('cat_icon');
			$ad_cat['cat_color'] = strtoupper("#".$this->input->post('cat_color'));
			$cek = $this->m_category->insert_category($ad_cat);

			if($cek){
				$this->session->set_flashdata('message_status', '1');
				$this->session->set_flashdata('message', 'Inserting Category Success');
			}else{
				$this->session->set_flashdata('message_status', '0');
				$this->session->set_flashdata('message', 'Inserting Category Failed');
			}
		}
		redirect("Admin/category");
	}

	public function update_category_process($param){
		if($this->input->post('btn_cat_update') !=""){
			if($this->input->post('cat_name') != ""){
				$update_cat['cat_name'] = $this->input->post('cat_name');	
			}

			if($this->input->post('cat_icon') != ""){
				$update_cat['cat_icon'] = $this->input->post('cat_icon');	
			}

			if($this->input->post('cat_color') != ""){
				$update_cat['cat_color'] = $this->input->post('cat_color');	
			}

			$update_cat['cat_id'] = $param;

			$cek = $this->m_category->update_category($update_cat);

			if($cek){
				$this->session->set_flashdata('message_status', '1');
				$this->session->set_flashdata('message', 'Updating Category Success');
			}else{
				$this->session->set_flashdata('message_status', '0');
				$this->session->set_flashdata('message', 'Updating Category Failed');
			}
		}
		redirect("Admin/edit_category/$param");
	}

	public function delete_category_process($param){
		if($this->input->post('btn_cat_delete') !=""){
			$cek = $this->m_category->delete_category($param);

			if($cek){
				$this->session->set_flashdata('message_status', '1');
				$this->session->set_flashdata('message', 'Deleting Category Success');
			}else{
				$this->session->set_flashdata('message_status', '0');
				$this->session->set_flashdata('message', 'Deleting Category Failed');
			}
		}
		redirect("Admin/delete_category/$param");
	}
}

/* End of file Category.php */
/* Location: ./application/controllers/Category.php */